package com.maoye.ossp.biz.statement.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.maoye.ossp.biz.statement.entity.StatementReadJustDetail;
import com.maoye.ossp.biz.statement.entity.StatementReceiveDetail;
import com.maoye.ossp.biz.statement.service.StatementReceiveDetailService;
import com.maoye.ossp.common.excel.ExportExcel;
/**
 * 验收单明细controller类
 * @author yanghao
 *
 */
@Controller
@RequestMapping(value = "biz/statement/statementReceiveDetail/")
public class StatementReceiveDetailController {
	
	@Resource
	private StatementReceiveDetailService statementReceiverDetailService;
	/**
	 * 验收单明细列表展示
	 * @param statementReceiveDetail
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "list")
	public String list(StatementReceiveDetail statementReceiveDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String billNo = statementReceiveDetail.getBillNo();
		Map map = new HashMap();
		map.put("billNo", billNo);
		List<StatementReceiveDetail> list = statementReceiverDetailService.getByBillNo(map);
		model.addAttribute("billNo", billNo);
		model.addAttribute("list", list);
		return "/biz/statement/statementReceiveDetail/list";
	}
	/**
	 * 验收单明细详细展示
	 * @param statementReceiveDetail
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "view")
	public String view(StatementReceiveDetail statementReceiveDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		String id = statementReceiveDetail.getId().toString();
		StatementReceiveDetail receiveDetail = statementReceiverDetailService.get(id);
		model.addAttribute("statementReceiveDetail", receiveDetail);
		return "/biz/statement/statementReceiveDetail/view";
	}
	/**
	 * 导出数据到Excel
	 * @param request
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping(value = "{billNo}/exportExcel")
	public String exportExcel (@PathVariable String billNo,HttpServletRequest request,Model model,RedirectAttributes redirectAttributes){
		Map map = new HashMap();
		map.put("billNo", billNo);
		List<StatementReceiveDetail> list = statementReceiverDetailService.getByBillNo(map);
		ExportExcel.exportExcel(billNo+"验收单明细表", list, StatementReceiveDetail.class, request);
		return "/excel/exceportToExcel";
	}
	public StatementReceiveDetailService getStatementReceiverDetailService() {
		return statementReceiverDetailService;
	}

	public void setStatementReceiverDetailService(
			StatementReceiveDetailService statementReceiverDetailService) {
		this.statementReceiverDetailService = statementReceiverDetailService;
	}
	
}
